#include "http.hpp"

//登录
void Login(HttpRequest& req, HttpResponse& rep)
{
    std::string text = "hello, " + req.Args();
    rep.SetHeader("Content-Type", "text/plain");
    rep.SetHeader("Content-Length", std::to_string(text.size()));
    rep.SetText(text);
    rep.SetCode(200);
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " port" << std::endl;
        exit((int)exit_code::USAGE_ERR);
    }

    std::unique_ptr<Http> http = std::make_unique<Http>(std::stoi(argv[1]));
    http->RegisterService("/login", Login);
    http->Start();
    
    return 0;
}
